package com.bawei.model_sevent.Activity.IM;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.bawei.model_sevent.Activity.MainActivity;
import com.bawei.model_sevent.R;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;

public class MainActivity_login extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_login);

        EMClient.getInstance().logout(true);
        
        EMClient.getInstance().login("zhangsan","aa125125",new EMCallBack() {//回调
            @Override
            public void onSuccess() {
                EMClient.getInstance().groupManager().loadAllGroups();
                EMClient.getInstance().chatManager().loadAllConversations();
                Log.d("main", "登录聊天服务器成功！");
                
                //存sp
                getSharedPreferences("im",MODE_PRIVATE).edit().putString("username","zhangsan").commit();
                //跳转页面
                Intent intent = new Intent(MainActivity_login.this, MainActivity.class);
                startActivity(intent);
            }

            @Override
            public void onProgress(int progress, String status) {

            }

            @Override
            public void onError(int code, String message) {
                System.out.println("==============="+message);
                Log.d("main", "登录聊天服务器失败！");
            }
        });
    }
}